def is_prime(s):
    for k in range(2, int(s ** 0.5) + 1):
        if s % k == 0:
            return False
    return True


n = input()
max_prime = 0
qq = []
z = 0
result = 0
n1 = n[0:1]
n2 = n[1:2]
n3 = n[2:3]
n4 = n[3:4]
qq.append(n1)
qq.append(n2)
qq.append(n3)
qq.append(n4)
rez2 = is_prime(int(n))
if len(n) == 4:
    for iii in range(1):
        if (rez2 is True) and (int(n) > max_prime):
            max_prime = int(n)
            z = 1
        if z == 1:
            print(max_prime)
            break
        for i in range(2):
            rez3 = is_prime(int(qq[i] + qq[i + 1] + qq[i + 2]))
            if (rez3 is True) and ((int(qq[i] + qq[i + 1] + qq[i + 2])) > max_prime):
                max_prime = (int(qq[i] + qq[i + 1] + qq[i + 2]))
                z = 3
        if z == 3:
            print(max_prime)
            break
        for i in range(3):
            rez1 = is_prime(int(qq[i] + qq[i + 1]))
            if (rez1 is True) and ((int(qq[i] + qq[i + 1])) > max_prime):
                max_prime = (int(qq[i] + qq[i + 1]))
                z = 2
        if z == 2:
            print(max_prime)
            break
        if z == 0:
            print(0)
            break
else:
    print(0)
